package com.yjt.common.hibernate.id;

import java.io.Serializable;

import org.hibernate.type.Type;

public class DefaultIdDecorator implements IdDecorator {

	@Override
	@SuppressWarnings("rawtypes")
	public Serializable decorator(Long id, Type type) throws SequenceGeneratorException{
		Class clazz = type.getReturnedClass();
		if ( clazz==Long.class ) {
			return id;
		}
		else if ( clazz==Integer.class ) {
			return new Integer( id.intValue() );
		}
		else if ( clazz==Short.class ) {
			return new Short( id.shortValue() );
		}
		else if ( clazz==String.class ) {
			return id.toString();
		}
		else {
			throw new SequenceGeneratorException("default id decorator not support the id type : " + clazz.getName());
		}
	}

}
